<template>
    <div>
        <p style="font-weight: bold" class="interfaceHead"><i class="el-icon-s-promotion"></i>信息上传</p>
        <el-divider></el-divider>
        <el-form ref="form" :model="formSup" label-width="80px">
            <el-form-item label="单位名称">
                <el-input placeholder="请输入注册企业单位名称" v-model="formSup.companyName"></el-input>
            </el-form-item>

            <el-form-item label="人员卫生">
                <el-select v-model="formSup.facilityR" placeholder="请选择">
                    <el-option
                            v-for="item in result"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="设施卫生">
                <el-select v-model="formSup.staffR" placeholder="请选择">
                    <el-option
                            v-for="item in result"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="场地卫生">
                <el-select v-model="formSup.siteR" placeholder="请选择">
                    <el-option
                            v-for="item in result"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="检查结果">
                <el-select v-model="formSup.checkResult" placeholder="请选择">
                    <el-option
                            v-for="item in result"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="检查级别">
                <el-select v-model="formSup.classify" placeholder="请选择">
                    <el-option
                            v-for="item in grade"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="检查时间">
                <el-input placeholder="请输入xxxx年" v-model="formSup.year"></el-input>
                <el-input placeholder="请输入xx月" v-model="formSup.month"></el-input>
                <el-input placeholder="请输入xx日" v-model="formSup.day"></el-input>
            </el-form-item>


            <el-form-item>
                <el-upload
                        action="/check/uploadFile"
                        ref="uploadDemo"
                        list-type="picture-card"
                        :headers="headers"
                        :auto-upload="false"
                        multiple="false">
                    <i slot="default" class="el-icon-plus"></i>
                    <div slot="file" slot-scope="{file}">
                        <img
                                class="el-upload-list__item-thumbnail"
                                :src="file.url" alt="">
                    </div>
                </el-upload>

            </el-form-item>
            <el-button type="primary" @click="submmitUp">提交</el-button>
        </el-form>

    </div>
</template>

<script>
    export default {
        name: "HealthSupApplySubmit",
        data() {
            return {
                formSup: {
                    companyName: '',
                    facilityR: '',
                    staffR: '',
                    siteR: '',
                    checkResult: '',
                    classify: '',
                    url: '',
                    year:'',
                    month:'',
                    day:'',
                },
                result: [ {
                    value: '合格',
                    label: '合格'
                }, {
                    value: '不合格',
                    label: '不合格'
                }],
                facilityR:[],
                staffR: [],
                siteR: [],
                checkResult: [],

                grade: [{
                    value: '1',
                    label: '复审检查'
                }, {
                    value: '2',
                    label: '终审检查'
                }, {
                    value: '3',
                    label: '日常检查'
                }],
                classify:[],
            }
        },
        computed: {
            headers: function () {
                return {
                    "Authorization": `${localStorage.getItem('token')}`
                }
            }
        },
        methods: {
            submmitUp() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        const _this = this;
                        this.postRequest('/check/upload', this.formSup).then(resp => {
                            if (resp) {
                                _this.$refs.uploadDemo.submit();
                                if (resp) {
                                    console.log(resp)
                                    this.$router.replace('/healthSup/healthsupapply');
                                    this.$message({
                                    message: '提交成功',
                                    type: 'success'})
                                }
                            }
                        })

                    } else {
                        this.$message.error('提交失败！');
                        return false;
                    }
                });
            },

        }
    }
</script>

<style scoped>

</style>
